package cn.occgmat.controller;

import cn.occgmat.entity.RbsystemTimetable;
import cn.occgmat.service.RbsystemTimetableService;
import cn.occgmat.util.BaseResponse;
import cn.occgmat.util.StatusCode;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.util.List;

/**
 * 车次表（时刻表）(RbsystemTimetable)表控制层
 *
 * @author makejava
 * @since 2021-03-27 10:01:54
 */
@RestController
@RequestMapping("rbsystemTimetable")
public class RbsystemTimetableController {
    /**
     * 服务对象
     */
    @Resource
    private RbsystemTimetableService rbsystemTimetableService;

    /**
     * 分页查询车次信息
     *
     * @param page  当前页数
     * @param limit 每页数
     * @return json数据
     */
    @GetMapping(value = "selectPage")
    public BaseResponse<RbsystemTimetable> selectPage(int page, int limit) {
        return this.rbsystemTimetableService.queryAllByLimit(page, limit);
    }

    /**
     * 更新单条车次信息
     */
    @PostMapping(value = "update")
    public BaseResponse<?> update(@RequestBody RbsystemTimetable rbsystemTimetable) {
        return this.rbsystemTimetableService.update(rbsystemTimetable);
    }


    /**
     * 添加信息
     */
    @PostMapping(value = "add")
    public BaseResponse<?> add(@RequestBody RbsystemTimetable rbsystemTimetable) {
        RbsystemTimetable addedTimetable = rbsystemTimetableService.insert(rbsystemTimetable);
        return addedTimetable != null ? new BaseResponse<>(StatusCode.Success) : new BaseResponse<>(StatusCode.Fail);
    }

    /**
     * 删除信息
     */
    @GetMapping(value = "delete")
    public BaseResponse<?> delete(Integer id) {
        boolean result = rbsystemTimetableService.deleteById(id);
        return result ? new BaseResponse<>(StatusCode.Success) : new BaseResponse<>(StatusCode.Fail);
    }

}
